/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import model.*;
import controller.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.event.TableModelEvent;
/**
 *
 * @author Carol
 */
public class frm_conta extends javax.swing.JFrame {

    /**
     * Creates new form frm_conta
     */
    TabelaBuscaCliente modelo = new TabelaBuscaCliente();
    TabelaBuscaConta modelo2 = new TabelaBuscaConta();
    
    public frm_conta() {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setTitle("Banco Internacional de TADS - Conta");
        //Inicializa o Combo de tipo de conta
        cboTipoConta.removeAllItems();
        cboTipoConta.addItem("SELECIONE UM TIPO DE CONTA");
        cboTipoConta.addItem("CONTA CORRENTE");
        cboTipoConta.addItem("CONTA INVESTIMENTO");
        //Inicializa os combos de busca
        //cboBuscar 1
        cboBuscar.removeAllItems();
        cboBuscar.addItem("CPF");
        cboBuscar.addItem("RG");
        cboBuscar.addItem("NOME");
        cboBuscar.addItem("SOBRENOME");
        //cboBuscar 2
        cboBuscar2.removeAllItems();
        cboBuscar2.addItem("CPF");
        cboBuscar2.addItem("RG");
        cboBuscar2.addItem("NOME");
        cboBuscar2.addItem("SOBRENOME");
        //Inicializando a tabela de cliente
        tblBuscarCliente.setModel(modelo);
        tblBuscarCliente.getColumnModel().getColumn(0).setHeaderValue("CPF");
        tblBuscarCliente.getColumnModel().getColumn(1).setHeaderValue("RG");
        tblBuscarCliente.getColumnModel().getColumn(2).setHeaderValue("NOME");
        tblBuscarCliente.getColumnModel().getColumn(3).setHeaderValue("SOBRENOME");
        tblBuscarCliente.getColumnModel().getColumn(4).setHeaderValue("ENDEREÇO");
        try {
            ClienteDAO cli = new ClienteDAO();
            List<Cliente> lista;
            lista = cli.listarClienteSConta();
            modelo.setListaClientes(lista);
        } catch (Exception ex) {
            Logger.getLogger(frm_conta.class.getName()).log(Level.SEVERE, null, ex);
        }
        // Tabela de conta
        tblBuscaConta.setModel(modelo2);
        tblBuscaConta.getColumnModel().getColumn(0).setHeaderValue("Numero Conta");
        tblBuscaConta.getColumnModel().getColumn(1).setHeaderValue("Proprietário da Conta");
        tblBuscaConta.getColumnModel().getColumn(2).setHeaderValue("Tipo da Conta");
        try{
            ContaDAO contadao = new ContaDAO();
            ClienteConta cliconta = new ClienteConta();
            List<Conta> listaConta;
            List<ClienteConta> listaCliConta;
            listaConta = contadao.listarConta();
            listaCliConta = cliconta.listar(listaConta);
            modelo2.setListaConta(listaCliConta);
                      
            //Evento para ordenação quando clicar no nome da coluna - aba cadastro
            tblBuscarCliente.getTableHeader().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    try{
                        ClienteDAO clidao = new ClienteDAO();
                        List<Cliente> lista = clidao.listarClienteSConta();
                        int numCol = tblBuscarCliente.columnAtPoint(e.getPoint());
                        //Ordena por CPF
                        if(numCol == 0){
                            Collections.sort(lista, new ComparaCPF());
                            modelo.setListaClientes(lista);
                        }
                        //Ordena por RG
                        if(numCol == 1){
                            Collections.sort(lista, new ComparaRG());
                            modelo.setListaClientes(lista);
                        }
                        //Ordena por Nome
                        if (numCol == 2){
                            Collections.sort(lista, new ComparaNome());
                            modelo.setListaClientes(lista);
                        }
                        //Ordena por Sobrenome
                        if (numCol == 3){
                            Collections.sort(lista, new ComparaSobrenome());
                            modelo.setListaClientes(lista);
                        }
                        //Ordena por Endereco
                        if (numCol == 4){
                            Collections.sort(lista, new ComparaEndereco());
                            modelo.setListaClientes(lista);
                        }
                    }catch(Exception ex){
                        Logger.getLogger(frm_cliente.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });     
            
            
            
        }catch (Exception ex){
            Logger.getLogger(frm_conta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlHead = new javax.swing.JPanel();
        lblConta = new javax.swing.JLabel();
        pnlAbas = new javax.swing.JTabbedPane();
        tabAcesso = new javax.swing.JPanel();
        lblBuscar = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        cboBuscar = new javax.swing.JComboBox();
        lblBuscarPor = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblBuscaConta = new javax.swing.JTable();
        cmdBuscar = new javax.swing.JButton();
        cmdVisualizar = new javax.swing.JButton();
        tabCadastro = new javax.swing.JPanel();
        lbldadosConta = new javax.swing.JLabel();
        lblDadosCliente = new javax.swing.JLabel();
        lblBuscar2 = new javax.swing.JLabel();
        txtBuscar2 = new javax.swing.JTextField();
        lblBuscarPor2 = new javax.swing.JLabel();
        cboBuscar2 = new javax.swing.JComboBox();
        cmdBuscar2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblBuscarCliente = new javax.swing.JTable();
        lblTipoConta = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lblPropCont = new javax.swing.JLabel();
        lblcpf = new javax.swing.JLabel();
        lblLimite = new javax.swing.JLabel();
        lblMontMin = new javax.swing.JLabel();
        lblDepMin = new javax.swing.JLabel();
        cmdCadCont = new javax.swing.JButton();
        lblNomeProp = new javax.swing.JLabel();
        lblCpfProp = new javax.swing.JLabel();
        cboTipoConta = new javax.swing.JComboBox();
        txtDepini = new javax.swing.JTextField();
        txtLimite = new javax.swing.JTextField();
        txtMontMin = new javax.swing.JTextField();
        txtDepMin = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblConta.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        lblConta.setText("Conta");

        lblBuscar.setText("Buscar: ");

        cboBuscar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cboBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboBuscarActionPerformed(evt);
            }
        });

        lblBuscarPor.setText("Busar Por:");

        tblBuscaConta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblBuscaConta);

        cmdBuscar.setText("Buscar");
        cmdBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                cmdBuscarMouseReleased(evt);
            }
        });

        cmdVisualizar.setText("Visualizar Conta");
        cmdVisualizar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                cmdVisualizarMouseReleased(evt);
            }
        });
        cmdVisualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdVisualizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabAcessoLayout = new javax.swing.GroupLayout(tabAcesso);
        tabAcesso.setLayout(tabAcessoLayout);
        tabAcessoLayout.setHorizontalGroup(
            tabAcessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabAcessoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabAcessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                    .addGroup(tabAcessoLayout.createSequentialGroup()
                        .addComponent(lblBuscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBuscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblBuscarPor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cboBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmdBuscar))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tabAcessoLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(cmdVisualizar)))
                .addContainerGap())
        );
        tabAcessoLayout.setVerticalGroup(
            tabAcessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabAcessoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabAcessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBuscar)
                    .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblBuscarPor)
                    .addComponent(cmdBuscar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmdVisualizar)
                .addContainerGap())
        );

        pnlAbas.addTab("Acesso", tabAcesso);

        lbldadosConta.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        lbldadosConta.setText("Dados da conta");

        lblDadosCliente.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        lblDadosCliente.setText("Dados do cliente");

        lblBuscar2.setText("Buscar: ");

        lblBuscarPor2.setText("Busar Por:");

        cboBuscar2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cboBuscar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboBuscar2ActionPerformed(evt);
            }
        });

        cmdBuscar2.setText("Buscar");
        cmdBuscar2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                cmdBuscar2MouseReleased(evt);
            }
        });

        tblBuscarCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblBuscarCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tblBuscarClienteMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblBuscarClienteMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblBuscarCliente);

        lblTipoConta.setText("Tipo de conta:");

        jLabel1.setText("Depósito Inicial:");

        lblPropCont.setText("Proprietário da conta:");

        lblcpf.setText("CPF:");

        lblLimite.setText("Limite:");

        lblMontMin.setText("Montante Mínimo:");

        lblDepMin.setText("Depósito Mínimo:");

        cmdCadCont.setText("Cadastrar");
        cmdCadCont.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                cmdCadContMouseReleased(evt);
            }
        });
        cmdCadCont.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdCadContActionPerformed(evt);
            }
        });

        lblNomeProp.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        lblNomeProp.setText("PROPRIETÁRIO NÃO SELECIONADO");

        lblCpfProp.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        lblCpfProp.setText("PROPRIETÁRIO NÃO SELECIONADO");

        cboTipoConta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cboTipoConta.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboTipoContaItemStateChanged(evt);
            }
        });
        cboTipoConta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboTipoContaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabCadastroLayout = new javax.swing.GroupLayout(tabCadastro);
        tabCadastro.setLayout(tabCadastroLayout);
        tabCadastroLayout.setHorizontalGroup(
            tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabCadastroLayout.createSequentialGroup()
                        .addComponent(lblBuscar2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBuscar2, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblBuscarPor2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cboBuscar2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmdBuscar2))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tabCadastroLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(cmdCadCont))
                    .addGroup(tabCadastroLayout.createSequentialGroup()
                        .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDadosCliente)
                            .addComponent(lbldadosConta)
                            .addGroup(tabCadastroLayout.createSequentialGroup()
                                .addComponent(lblcpf)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblCpfProp, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(tabCadastroLayout.createSequentialGroup()
                                .addComponent(lblPropCont)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblNomeProp, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tabCadastroLayout.createSequentialGroup()
                                    .addComponent(lblDepMin)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtDepMin))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tabCadastroLayout.createSequentialGroup()
                                    .addComponent(lblMontMin)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtMontMin))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tabCadastroLayout.createSequentialGroup()
                                    .addComponent(lblLimite)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtLimite))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tabCadastroLayout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtDepini))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tabCadastroLayout.createSequentialGroup()
                                    .addComponent(lblTipoConta)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(cboTipoConta, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        tabCadastroLayout.setVerticalGroup(
            tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBuscar2)
                    .addComponent(txtBuscar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboBuscar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblBuscarPor2)
                    .addComponent(cmdBuscar2))
                .addGap(18, 18, 18)
                .addComponent(lblDadosCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addComponent(lbldadosConta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPropCont)
                    .addComponent(lblNomeProp))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblcpf)
                    .addComponent(lblCpfProp))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTipoConta)
                    .addComponent(cboTipoConta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtDepini, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblLimite)
                    .addComponent(txtLimite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMontMin)
                    .addComponent(txtMontMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDepMin)
                    .addComponent(txtDepMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                .addComponent(cmdCadCont)
                .addContainerGap())
        );

        pnlAbas.addTab("Cadastro", tabCadastro);

        javax.swing.GroupLayout pnlHeadLayout = new javax.swing.GroupLayout(pnlHead);
        pnlHead.setLayout(pnlHeadLayout);
        pnlHeadLayout.setHorizontalGroup(
            pnlHeadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlHeadLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlHeadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlHeadLayout.createSequentialGroup()
                        .addComponent(lblConta)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlHeadLayout.createSequentialGroup()
                        .addGroup(pnlHeadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(pnlAbas, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator2))
                        .addGap(20, 20, 20))))
        );
        pnlHeadLayout.setVerticalGroup(
            pnlHeadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlHeadLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblConta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlAbas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlHead, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlHead, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cboBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboBuscarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboBuscarActionPerformed

    private void cboBuscar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboBuscar2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboBuscar2ActionPerformed

    private void cmdCadContActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCadContActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmdCadContActionPerformed

    private void cmdVisualizarMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdVisualizarMouseReleased
        int linha = tblBuscaConta.getSelectedRow();
        ClienteConta cliconta = modelo2.getConta(linha);
        frm_saldo tela = new frm_saldo(cliconta.getNconta());
        tela.show();
    }//GEN-LAST:event_cmdVisualizarMouseReleased

    private void cboTipoContaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboTipoContaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboTipoContaActionPerformed

    private void cboTipoContaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboTipoContaItemStateChanged
        // TODO add your handling code here:
        //pega o indice selecionado
        int itemSelecionado = cboTipoConta.getSelectedIndex();
        switch(itemSelecionado){
            //Conta Corrente
            case 1:
                if("NÃO SE APLICA".equals(txtLimite.getText())){
                    txtLimite.setText("");
                    txtLimite.setEditable(true);
                }
                txtMontMin.setText("NÃO SE APLICA");
                txtDepMin.setText("NÃO SE APLICA");
                txtMontMin.setEditable(false);
                txtDepMin.setEditable(false);
            break;
            //Conta Investimento
            case 2:
                if("NÃO SE APLICA".equals(txtMontMin.getText())){ 
                    txtMontMin.setText("");
                    txtMontMin.setEditable(true);
                }
                if("NÃO SE APLICA".equals(txtDepMin.getText())){
                    txtDepMin.setText("");                           
                    txtDepMin.setEditable(true);
                };
                txtLimite.setText("NÃO SE APLICA");
                txtLimite.setEditable(false);
            break;
            //"Selecione um tipo de conta"
            default:
                if("NÃO SE APLICA".equals(txtLimite.getText())) txtLimite.setText("");
                if("NÃO SE APLICA".equals(txtMontMin.getText())) txtMontMin.setText("");
                if("NÃO SE APLICA".equals(txtDepMin.getText())) txtDepMin.setText("");
                txtMontMin.setEditable(true);
                txtDepMin.setEditable(true);
                txtLimite.setEditable(true);
            break;
        }
                
        
    }//GEN-LAST:event_cboTipoContaItemStateChanged

    private void tblBuscarClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBuscarClienteMouseClicked
           int linha;
               linha = tblBuscarCliente.getSelectedRow();
               Cliente cliente = modelo.getCliente(linha);
              
               lblNomeProp.setText(cliente.getNome() + " " + cliente.getSobrenome());
               lblCpfProp.setText(cliente.getCpf());
                        
    }//GEN-LAST:event_tblBuscarClienteMouseClicked

    private void tblBuscarClienteMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBuscarClienteMouseReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_tblBuscarClienteMouseReleased

    private void cmdCadContMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdCadContMouseReleased
        String cpf = lblCpfProp.getText();
        if(!"PROPRIETÁRIO NÃO SELECIONADO".equals(cpf)){
            double depini = Double.parseDouble(txtDepini.getText());
            int tipo = cboTipoConta.getSelectedIndex();
            int nconta;
            Cliente cli = new Cliente();
            
            try {
                ClienteDAO clidao = new ClienteDAO();
                cli = clidao.consultarCliente(cpf);
            } catch (Exception ex) {
                Logger.getLogger(frm_conta.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            switch(tipo){        
                case 1:
                    //mont min dep min não se aplica
                    double limite = Double.parseDouble(txtLimite.getText());
                    //passa o 0 como nconta porque ele auto incrment então não faz difereça
                    ContaCorrente contac = new ContaCorrente(0,depini, depini, limite);
                    try {
                        //cria os dao necessários
                        ContaDAO contadao = new ContaDAO();
                        ContaCorrenteDAO cc = new ContaCorrenteDAO();
                        ClienteDAO clidao = new ClienteDAO();
                        //cadastra a conta e vincula o cliente a conta
                        cc.inserirContaCorrente(contac, cli);
                        nconta = contadao.buscarNConta(cpf);
                        clidao.vinculaCliente(cpf, nconta);
                        JOptionPane.showMessageDialog(null, "Conta Corrente cadastrada com sucesso", "Sucesso!", JOptionPane.INFORMATION_MESSAGE);
                    
                        //ju - Atualizar a busca assim que cadastrar a conta e limpar campos
                        List<Cliente> lista = clidao.listarClienteSConta();
                        modelo.setListaClientes(lista);
                        Limpar();
            
                        ClienteConta cliconta = new ClienteConta();
                        List<Conta> listaConta;
                        List<ClienteConta> listaCliConta;
                        listaConta = contadao.listarConta();
                        listaCliConta = cliconta.listar(listaConta);
                        modelo2.setListaConta(listaCliConta);
                        
                    } catch (Exception ex) {
                        Logger.getLogger(frm_conta.class.getName()).log(Level.SEVERE, null, ex);
                    }

                break;
                case 2:
                    //sem limite
                    double montmin = Double.parseDouble(txtMontMin.getText());
                    double depmin = Double.parseDouble(txtDepMin.getText());
                    //passa o 0 como nconta porque ele auto incrment então não faz difereça
                    ContaInvestimento contai = new ContaInvestimento(0,depini, depini, montmin, depmin);
                    if(depini < depmin){
                        //msg "Deposito inicial menor que o deposito minimo permitido!"
                        JOptionPane.showMessageDialog(null,"O depósito inicial é menor do que o depósito mínimo permitido!","Atenção",JOptionPane.ERROR_MESSAGE);
                        break;
                    }else if(depini < montmin){                    
                        //msg "Deposito inicial menor que o montante mínimo que a conta necessita!"
                        JOptionPane.showMessageDialog(null,"O depósito inicial é menor do que o montante mínimo permitido!","Atenção",JOptionPane.ERROR_MESSAGE);
                        break;
                    }else{
                        //cadastra a conta
                        try {
                            ContaInvestimentoDAO ci  = new ContaInvestimentoDAO();
                            ContaDAO contadao = new ContaDAO();
                            ClienteDAO clidao = new ClienteDAO();
                            
                            ci.inserirContaInvestimento(contai, cli);
                            nconta = contadao.buscarNConta(cpf);
                            clidao.vinculaCliente(cpf, nconta);
                            JOptionPane.showMessageDialog(null, "Conta Investimento cadastrada com sucesso", "Sucesso!", JOptionPane.INFORMATION_MESSAGE);
                        
                            //ju - Atualizar a busca assim que cadastrar a conta e limpar campos
                            List<Cliente> lista = clidao.listarClienteSConta();
                            modelo.setListaClientes(lista);
                            Limpar();
                            ClienteConta cliconta = new ClienteConta();
                            List<Conta> listaConta;
                            List<ClienteConta> listaCliConta;
                            listaConta = contadao.listarConta();
                            listaCliConta = cliconta.listar(listaConta);
                            modelo2.setListaConta(listaCliConta);
                        } catch (Exception ex) {
                            Logger.getLogger(frm_conta.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                break;
                default:
                    contai = null;
                    contac = null;
                    JOptionPane.showMessageDialog(null, "Selecione um tipo de conta", "Atenção", JOptionPane.ERROR_MESSAGE );
                break;

            }  
        }else{
            JOptionPane.showMessageDialog(null, "Selecione o proprietário da conta na tabela acima", "Atenção", JOptionPane.ERROR_MESSAGE );
        }
    }//GEN-LAST:event_cmdCadContMouseReleased
 public void Limpar(){
        //Método para limpar os campos de texto do cadastro
        lblNomeProp.setText("PROPRIETÁRIO NÃO SELECIONADO");
        lblCpfProp.setText("PROPRIETÁRIO NÃO SELECIONADO");
        cboTipoConta.setSelectedIndex(0);
        txtDepini.setText("");
        txtLimite.setText("");
        txtMontMin.setText("");
        txtDepMin.setText("");
    }
 
    
    private void cmdVisualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdVisualizarActionPerformed

    }//GEN-LAST:event_cmdVisualizarActionPerformed

 
    private void cmdBuscarMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdBuscarMouseReleased
         // TODO add your handling code here:
        //Pega os parâmetros de busca
        //0 - CPF        
        //1 - RG          
        //2 - NOME           
        //3 - SOBRENOME
        int pBusca = cboBuscar.getSelectedIndex();
        String str = txtBuscar.getText();
        
        try {       
            ClienteContaDAO clicontadao = new ClienteContaDAO();
            List<ClienteConta> listaCliConta;
            listaCliConta = clicontadao.busca(str, pBusca);
           
            if(listaCliConta.isEmpty()){
                JOptionPane.showMessageDialog(null, "A busca retornou 0 registros!", "Não encontrado",JOptionPane.INFORMATION_MESSAGE);
            }else{
                //chama o metodo pra atualizar a tabela
                modelo2.setListaConta(listaCliConta);
            }
        } catch (Exception ex) {
            Logger.getLogger(frm_cliente.class.getName()).log(Level.SEVERE, null, ex);
        }    
    }//GEN-LAST:event_cmdBuscarMouseReleased

    private void cmdBuscar2MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdBuscar2MouseReleased
         // TODO add your handling code here:
        //Pega os parâmetros de busca
        //0 - CPF        
        //1 - RG          
        //2 - NOME           
        //3 - SOBRENOME
        int pBusca = cboBuscar2.getSelectedIndex();
        String str = txtBuscar2.getText();
        //cria um novo cliente DAO e uma lista para preencher a tabela
        try {            
            ClienteDAO clidao = new ClienteDAO();
            List<Cliente> lista;
            //faz a busca
            lista = clidao.busca2(str, pBusca);
            if(lista.isEmpty()){
                JOptionPane.showMessageDialog(null, "A busca retornou 0 registros!", "Não encontrado",JOptionPane.INFORMATION_MESSAGE);
            }else{
                //chama o metodo pra atualizar a tabela
                modelo.setListaClientes(lista);
            }
        } catch (Exception ex) {
            Logger.getLogger(frm_cliente.class.getName()).log(Level.SEVERE, null, ex);
        }    
    }//GEN-LAST:event_cmdBuscar2MouseReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frm_conta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frm_conta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frm_conta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frm_conta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frm_conta().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cboBuscar;
    private javax.swing.JComboBox cboBuscar2;
    private javax.swing.JComboBox cboTipoConta;
    private javax.swing.JButton cmdBuscar;
    private javax.swing.JButton cmdBuscar2;
    private javax.swing.JButton cmdCadCont;
    private javax.swing.JButton cmdVisualizar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lblBuscar;
    private javax.swing.JLabel lblBuscar2;
    private javax.swing.JLabel lblBuscarPor;
    private javax.swing.JLabel lblBuscarPor2;
    private javax.swing.JLabel lblConta;
    private javax.swing.JLabel lblCpfProp;
    private javax.swing.JLabel lblDadosCliente;
    private javax.swing.JLabel lblDepMin;
    private javax.swing.JLabel lblLimite;
    private javax.swing.JLabel lblMontMin;
    private javax.swing.JLabel lblNomeProp;
    private javax.swing.JLabel lblPropCont;
    private javax.swing.JLabel lblTipoConta;
    private javax.swing.JLabel lblcpf;
    private javax.swing.JLabel lbldadosConta;
    private javax.swing.JTabbedPane pnlAbas;
    private javax.swing.JPanel pnlHead;
    private javax.swing.JPanel tabAcesso;
    private javax.swing.JPanel tabCadastro;
    private javax.swing.JTable tblBuscaConta;
    private javax.swing.JTable tblBuscarCliente;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtBuscar2;
    private javax.swing.JTextField txtDepMin;
    private javax.swing.JTextField txtDepini;
    private javax.swing.JTextField txtLimite;
    private javax.swing.JTextField txtMontMin;
    // End of variables declaration//GEN-END:variables
}
